package com.example.main;

import com.alipay.sofa.rpc.config.ProviderConfig;
import com.alipay.sofa.rpc.config.RegistryConfig;
import com.alipay.sofa.rpc.config.ServerConfig;
import com.example.service.HelloService;
import com.example.service.impl.HelloServiceImpl;

public class SofaRpcServerMain {
    public static void main(String[] args) {
        // 指定注册中心
        RegistryConfig registryConfig = new RegistryConfig()
                .setProtocol("zookeeper")
                .setAddress("127.0.0.1:2181");
        
        // 指定服务端协议和地址
        ServerConfig serverConfig = new ServerConfig()
                .setProtocol("bolt")
                .setPort(12345)
                .setDaemon(false);
        
        RegistryConfig registryConfigLocal = new RegistryConfig()
     	         .setProtocol("local")
     	         .setFile("./logs/localRegistry.reg");
        
        RegistryConfig registryConfigConsul = new RegistryConfig()
     	         .setProtocol("consul")
     	         .setAddress("127.0.0.1:8500");
        
        //　发布一个服务
        ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>()
                .setInterfaceId(HelloService.class.getName())
                .setRef(new HelloServiceImpl())
//                .setRegistry(registryConfigConsul)
                .setRegistry(registryConfigLocal)
                .setServer(serverConfig);
        providerConfig.export();
    }
}
